package com.ruoyi.web.zangchat.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.core.text.Convert;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.zangchat.domain.ChatLogThirdpay;
import com.ruoyi.web.zangchat.service.IChatLogThirdpayService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 第三方支付记录Controller
 * 
 * @author wudi
 * @date 2020-07-19
 */
@Controller
@RequestMapping("/zangchat/thirdpay")
public class ChatLogThirdpayController extends BaseController
{
    private String prefix = "zangchat/thirdpay";

    @Autowired
    private IChatLogThirdpayService chatLogThirdpayService;

    @RequiresPermissions("zangchat:thirdpay:view")
    @GetMapping()
    public String thirdpay()
    {
        return prefix + "/thirdpay";
    }

    /**
     * 查询第三方支付记录列表
     */
    @RequiresPermissions("zangchat:thirdpay:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(@RequestParam Map<String,Object> map)
    {
        startPage();
        return getDataTable(chatLogThirdpayService.chatLogThirdpayList(map));
    }

    /**
     * 导出第三方支付记录列表
     */
    @RequiresPermissions("zangchat:thirdpay:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ChatLogThirdpay chatLogThirdpay)
    {
        List<ChatLogThirdpay> list = chatLogThirdpayService.list(new QueryWrapper<>());
        ExcelUtil<ChatLogThirdpay> util = new ExcelUtil<ChatLogThirdpay>(ChatLogThirdpay.class);
        return util.exportExcel(list, "thirdpay");
    }

    /**
     * 新增第三方支付记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存第三方支付记录
     */
    @RequiresPermissions("zangchat:thirdpay:add")
    @Log(title = "第三方支付记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ChatLogThirdpay chatLogThirdpay)
    {
        return toAjax(chatLogThirdpayService.save(chatLogThirdpay));
    }

    /**
     * 修改第三方支付记录
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        ChatLogThirdpay chatLogThirdpay = chatLogThirdpayService.getById(id);
        mmap.put("chatLogThirdpay", chatLogThirdpay);
        return prefix + "/edit";
    }

    /**
     * 修改保存第三方支付记录
     */
    @RequiresPermissions("zangchat:thirdpay:edit")
    @Log(title = "第三方支付记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ChatLogThirdpay chatLogThirdpay)
    {
        return toAjax(chatLogThirdpayService.updateById(chatLogThirdpay));
    }

    /**
     * 删除第三方支付记录
     */
    @RequiresPermissions("zangchat:thirdpay:remove")
    @Log(title = "第三方支付记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(chatLogThirdpayService.removeByIds(Arrays.asList(Convert.toStrArray(ids))));
    }
}
